package com.example.lcode.greedy;

import java.util.Arrays;

/**
 * @version 1.0
 * @author: ChuJie_Lin
 * @since: 2021-10-11 12:50
 **/
public class Question452 {

    public int findMinArrowShots(int[][] points) {
        int res = 0;
        if (points == null || points.length == 0) {
            return res;
        }
        Arrays.sort(points, (o1, o2) -> {
            if (o1[0] > o2[0]) {
                return 1;
            } else if (o1[0] == o2[0]) {
                return 0;
            }
            return -1;
        });
        int max = points[0][1];
        int min = points[0][0];
        res ++;
        for (int i = 1; i < points.length; i++) {
            if(points[i][0] <= max) {
                max = Math.min(max, points[i][1]);
            } else {
                max = points[i][1];
                res ++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[][] arrs = {{1,2},{3,4},{5,6},{7,8}};
        Question452 question452 = new Question452();
        int i = question452.findMinArrowShots(arrs);
        System.out.println(i);
    }
//        [[1,2],[2,3],[3,4],[4,5]]
}
